package com.fanvil.videoconference;

import android.content.Context;
import android.view.Surface;

import com.fanvil.videoconference.FvlSurfaceHolder;
import com.fanvil.videoconference.FvlLogger;

public class FvlVideoWindow {
    private static FvlLogger sLogger = FvlLogger.getLogger(FvlVideoWindow.class.getSimpleName(), FvlLogger.DEBUG);

    private Surface mSurface = null;
    private Object mRenderer = null;
    private int mRole = -1;

    private static FvlVideoWindow sLocalInstance;
    private static FvlVideoWindow sRemoteInstance;

    public static FvlVideoWindow getLocal() {
        if (sLocalInstance == null) {
            sLocalInstance = new FvlVideoWindow();
            sLocalInstance.setRole(FvlSurfaceHolder.Role.LOCAL.value());
        }
        return sLocalInstance;
    }

    public static FvlVideoWindow getRemote() {
        if (sRemoteInstance == null) {
            sRemoteInstance = new FvlVideoWindow();
            sRemoteInstance.setRole(FvlSurfaceHolder.Role.REMOTE.value());
        }
        return sRemoteInstance;
    }

    public Object getRenderer() {
        return mRenderer;
    }

    public void setRenderer(Object renderer) {
        mRenderer = renderer;
    }

    public Surface getSurface() {
        return mSurface;
    }

    public void setSurface(Surface surface) {
        mSurface = surface;
    }

    public void setRole(int role) {
        mRole = role;
    }

    public boolean isValid() {
        sLogger.e("isValid"
                + ", mRenderer=" + mRenderer
                + ", mSurface=" + mSurface
                + ", Role=" + mRole);
        return mRenderer != null;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;

        if (getClass() != obj.getClass()) {
            return false;
        }

        FvlVideoWindow b = (FvlVideoWindow) obj;
        return mRole == b.mRole;
    }

    @Override
    public String toString() {
        return "FvlVideoWindow{"
                + ", mRenderer=" + mRenderer
                + ", mSurface=" + mSurface
                + ", Role=" + mRole
                + "}";
    }
}
